package com.euq.mapper;

import com.euq.entity.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeptMapper {
    @Select("select * from dept")
    List<Dept> listAll();
    @Select("select * from dept where id = #{id}")
    Dept findById(Long id);
    @Select("select * from dept where fullName = #{fullName}")
    Dept findByFullName(String fullName);
    @Select("select * from dept where pid = #{pid}")
    Dept findByPid(Long pid);
    @Insert({
            "INSERT INTO dept (create_by, create_time, modify_by, modify_time, fullname, num, pid, pids, simplename)",
            "VALUES(1,now(),1,now(),#{fullName},#{num},#{pid},#{pids},#{simpleName})"
    })
    Dept insert(Dept dept);
    @Update({"UPDATE dept",
            "SET create_by=1,",
            "create_time=now()",
            "modify_by=1",
            "modify_time=now()",
            "fullname=#{fullName}",
            "num=#{num}",
            "pid=#{pid}",
            "pids=#{pids}",
            "simplename=#{simpleName}",
            "WHERE id=#{id}"
    })
    Dept update(Dept dept);
    @Delete("delete from dept where id =#{id}")
    void deleteById(Long id);
    @Delete("DELETE FROM dept WHERE pids LIKE CONCAT('%', #{pids}, '%')")
    void deleteLikePids(String pids);
}
